package cn.itcast.consumer.controller;//package cn.itcast.consumer.controller;
//
//import cn.itcast.consumer.pojo.User;
//import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.client.RestTemplate;
//
//@RestController
//@RequestMapping("consumer")
//public class UserController {
//
//    @Autowired
//    private RestTemplate restTemplate;
//
//    @GetMapping("user/{id}")
//    @HystrixCommand(fallbackMethod = "queryUserByIdFallback")
//    public String queryUserById(@PathVariable("id") Long id) {
//        if(id == 1){
//            throw new RuntimeException("太忙了");
//        }
//
//        //user-service ----->ribbon----->eureka------->list<user-service>
//        //choose  ---->user-service: ip+port/user/3
//        String userJson = restTemplate.getForObject("http://user-service/user/" + id, String.class);
//
//        return userJson;
//    }
//
//    //回调方法和原始方法返回值类型一致，参数类型一致，
//    public String queryUserByIdFallback( Long id) {
//
//        return id+" 当前银行没钱，你爱咋咋地";
//    }
//}
